package com.exmaple.mall.web.interceptor;

import com.example.mall.common.Constants;
import org.checkerframework.checker.units.qual.A;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component
public class ShopLoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (null == request.getSession().getAttribute(Constants.SHOP_USER_SESSION_KEY)) {
            response.sendRedirect(request.getContextPath() + "/shop/login");
            return false;
        } else {
            return true;
        }
    }
}
